"""

Run the general solver routine blackbox.solve(...), which is designed to
handle an arbitrary matrix.

"""

from scipy import rand
from numpy import arange, array           
from pyamg import solve               
from pyamg.gallery import poisson         
from pyamg.util.linalg import norm        

if __name__ == '__main__':

    ##
    # Run solve(...) with the verbose option
    n = 100
    A = poisson((n,n),format='csr')         
    b = array(arange(A.shape[0]), dtype=float)
    print ""
    x = solve(A,b,verb=True)
    
    ##
    # Return the solver generated by solve(...) so that it can be used again
    print ""
    (x,ml) = solve(A,b,verb=True,return_solver=True,tol=1e-8)               
    # run for a new right-hand-side
    b2 = rand(b.shape[0],)
    print ""
    x2 = solve(A,b2,verb=True,existing_solver=ml,tol=1e-8)
    print ""

